package xdu.ble.common.advice;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import xdu.ble.common.enums.ExceptionCode;
import xdu.ble.common.exception.BLEException;
import xdu.ble.common.exception.ExceptionResponse;


@ControllerAdvice(basePackages = {"xdu.ble.auth.controller"})
//默认会拦截所有的有@XXXController的注解,包名必须和xdu.lz.common.advice交集不为空
//如把App放在xdu.lz下可以，但是放在xdu.lz.app下就不行，与xdu.lz.common.advice交集为空
//@ControllerAdvice(basePackages = "xdu.lz") //对xdu.lz包下的,只限于该包下的application
public class CommonExceptionHandler {
    @ExceptionHandler(BLEException.class)
    public ResponseEntity<ExceptionResponse> handlerException(BLEException e) {
        ExceptionCode em = e.getExceptionCode();
        return ResponseEntity.status(em.getCode()).body(new ExceptionResponse(em));
    }
}
